<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var deepestLeavesSum = function (root) {
      let count = 0
      const queue = []
      queue.push(root)
      while (queue.length) {
        count = 0
        const remove = queue.slice()
        queue.length = 0
        for (let i = 0; i < remove.length; i++) {
          count += remove[i].val
          if (remove[i].left) {
            queue.push(remove[i].left)
          }
          if (remove[i].right) {
            queue.push(remove[i].right)
          }
        }
      }
      return count
      return root
    };
    console.log(deepestLeavesSum([1, 2, 3, 4, 5, null, 6, 7, null, null, null, null, 8]));
  </script>
</body>

</html>